<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/bootstrap/css/alertify.core.css">
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/bootstrap/css/alertify.default.css">
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/Css/style.css"/>
    <link href="<%=request.getContextPath()%>/Css/jquery-ui.min.css"
          type="text/css" rel="stylesheet"/>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.11.3.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/bootstrap/js/alertify.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/ckform.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/common.js"></script>
    <script type="text/javascript"
            src="<%=request.getContextPath()%>/js/jquery-ui.min.js"></script>
            <style type="text/css">
            table th,td{
            	text-align: center;
            }
            </style>
</head>

<body>
<form id="playerform" class="form-inline definewidth m20" action="/" method="post">
	<
    <label><span>申请类型：</span><select id="selectApplicatType" name="applicatType">
    
    	<c:if test="${applicatType!=null and  applicatType=='0'}">
	    	<option value="0" selected="selected">申请代理</option>
    		<option value="1">申请退出俱乐部</option>
	    </c:if>
    	<c:if test="${applicatType!=null and  applicatType=='1'}">
	    	<option value="0" >申请代理</option>
    		<option value="1" selected="selected">申请退出俱乐部</option>
	    </c:if>
    	<c:if test="${applicatType==null}">
	    	<option value="0">申请代理</option>
    		<option value="1">申请退出俱乐部</option>
	    </c:if>
    </select>&nbsp;&nbsp;
    </label>
    <label><span>玩家ID：</span><input type="text" name="id" id="id" class="abc input-default"
                                    value="${playerId}">&nbsp;&nbsp;
    </label>
    <button type="button" class="btn btn-primary" onclick="queryPlayer();">查询</button>
</form>

<div  style="float: right; font-size: larger;margin-right: 40px;font-weight: bold">
    <span>注册人数：</span> <font id="allCount" size="6" color="#FF0000" > ${allCount}</font>
    <span>在线人数：</span><font id="onlineCount" size="6" color="#FF0000">${onlineCount}</font>
</div>
<table class="table table-bordered table-hover definewidth m10">
    <thead>
    <tr>
        <th width="5%">游戏ID</th>
        <th width="8%">昵称</th>
        <th width="5%">电话</th>
        <th width="5%">微信</th>
      	<th width="10%">申请类型</th>
        <th>申请原因</th>
        <th width="10%">备注</th>
        <th width="10%">申请时间</th>
        <th width="5%">是否已阅</th>
        <th width="8%">操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${list}" var="form">
        <tr>
            <td name="id">${form.playerId}</td>
            <td name="nickName">${form.name}</td>
            <td name="telPhone">${form.telPhone }</td>
            <td name="weixin">${form.weixin }</td>
            <td name="weixin"><c:if test="${form.applicatType==0 }">申请成为代理</c:if>
            <c:if test="${form.applicatType==1 }">申请退出俱乐部</c:if>
            </td>
            <td name="content">${form.content}</td>
            <td name="desc">${form.formDesc}</td>
            <td name="createTime"><fmt:formatDate value="${form.createTime }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
            <td name="watchFlag"><c:if test="${form.watchFlag==true}">是</c:if><c:if test="${form.watchFlag==false }">否</c:if></td>
            <td>
                <div class="btn-group">
				  <button type="button" class="btn btn-default" onclick="aleadyWatch(${form.id});">
				 	   处理
				  </button>
				  <button type="button" class="btn btn-default" data-toggle="modal" data-target="#formDescModal" data-desc="${form.formDesc }" data-formId="${form.id}" >
				 	   备注
				  </button>
				</div>
            </td>
        </tr>
    </c:forEach>
    </tbody>
    <tfoot>
    <tr bgcolor="EEF7FE">
        <td colspan="14" bgcolor="EEF7FE" class="f">
            <div align="right" style="bgcolor:EEF7FE" class="f">
                <jsp:include page="/common/pageUtil.jsp"></jsp:include>
            </div>
        </td>
    </tr>
    </tfoot>
</table>

<div id="addCoinDiv" style="display: none;">
    <form action="/" method="post" id="addCoinForm">
        <table  cellpadding="0" cellspacing="0">
            <tr >

                <td><label for="player_id"><span
                        style="color:#F00; margin-right:2px;">*</span>玩家账户：
                </label>
                </td>
                <td><input id="player_id" name="player_id" type='text'class="sp_t"
                           value="" readonly="readonly"/></td>
            </tr>
            <tr >
                <td><label for="amount"><span
                        style="color:#F00; margin-right:2px;">*</span>金额：
                </label>
                </td>
                <td><input id="amount" name="amount" type='text'class="sp_t"
                           value=""/></td>
            </tr>
            <tr >
                <td><label for="mahjong_coin"><span
                        style="color:#F00; margin-right:2px;">*</span>钻石：
                </label>
                </td>
                <td><input id="mahjong_coin" name="mahjong_coin" type='text'class="sp_t"
                           value=""/></td>
            </tr>

        </table>
    </form>
</div>

<div class="modal fade" id="formDescModal" tabindex="-1" role="dialog" data-keyboard="false" aria-labelledby="#modalTitle" aria-describedby="添加备注">
  <div class="modal-dialog" aria-hidden="true"  role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="modalTitle">修改备注</h4>
      </div>
      <div class="modal-body">
      <form class="form-horizontal" id="descForm">
		<div class="form-group">
				<input id="formId" name="formId" type="hidden" >
				<label for="inputPassword3" class="col-sm-2 control-label">内容:</label>
				<div class="col-sm-10">
        			<textarea id="formDesc" name="desc" placeholder="请输入备注" class="form-control" rows="3"></textarea>
        		</div>
		</div>
      </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" id="closeBtn" data-dismiss="modal" style="display: none;">关闭</button>
        <button type="button" class="btn btn-primary" id="addClubBtn" onclick="updateDesc()">确定</button>
      </div>
    </div>
  </div>
</div>
</body>
<script type="text/javascript">

	alertify.set({
		labels : {
			ok     : "确定",
			cancel : "取消"
		},
		delay : 5000,
		buttonReverse : false,
		buttonFocus   : "ok"
	});
	
	$('#formDescModal').on('show.bs.modal', function (event) {
		var button = $(event.relatedTarget);
		var desc = button.data('desc'),formId=button.data('formid');
		var modal = $(this);
		console.log(button.data("formId"));
		if(!formId){
			desc="获取申请单ID错误!";
		}
		modal.find('#formDesc').text(desc);
		modal.find('#formId').val(formId);
	})
	
	function updateDesc(){
		var form = document.getElementById("descForm");
        form.action = "<%=request.getContextPath()%>/club/getApplication.html";
        form.submit();
	}
	function aleadyWatch(formId){
		var form = document.getElementById("playerform");
        form.action = "<%=request.getContextPath()%>/club/getApplication.html?formId="+formId+"&watchFlag=1";
        form.submit();
	}
	
    // 下一页
    function getNextPage(page) {
        var form = document.getElementById("playerform");
        form.action = "<%=request.getContextPath()%>/player/queryPlayerList.html?pageIndex="+page;
        form.submit();
    }

    function queryPlayer() {
        var form = document.getElementById("playerform");
        form.action = "<%=request.getContextPath()%>/club/getApplication.html";
        form.submit();
    }
	//绑定代理
    function bingdingClub(playerId,el){
    	if(!playerId){
    		alert("获取玩家id失败");
    		return false;
    	}
    	initModal();
    	var playerClub;
    	$.post("<%=request.getContextPath()%>/club/getBindClub.html",{"playerId":playerId},function(data){
    			console.log(data);
    		if(data){
    			var result=$.parseJSON(data),clubInfo=result["data"];
    			if(clubInfo){
    				$("#alreadyInfo").find("#clubId").html(clubInfo["clubId"]);
    				$("#alreadyInfo").find("#clubName").html(clubInfo["clubName"]);
    				$("#alreadyInfo").find("#surplusDiamond").html(clubInfo["arrearage"]||0);
    				$("#alreadyInfo").data("clubInfo",clubInfo);
    				$("#alreadyInfo").show();
    			}
    		}
    		modalAlert(playerId);
    	},"json");
    }
    
	function clearBindClub(playerId,el){
    	if(!playerId){
    		alert("获取玩家id失败");
    		return false;
    	}
    	alertify.confirm("确定解除玩家所绑定的俱乐部?",function(e){
    		if(e){
		    	$.post("<%=request.getContextPath()%>/club/relieveBindClub.html",{"playerId":playerId},function(data){
		    			console.log(data);
		    		if(data){
		    			alertify.alert(data["msg"],function(){
		    				queryPlayer();
		    			});
		    		}
		    	},"json");
    		}else{
    			return false;
    		}
    	});
		
	}
	
	//弹出绑定窗口
    function modalAlert(playerId){
		$("#addBingClub").modal({"backdrop":"static"},'show');
		$("#addBingClub").data("playerId",playerId);
    }
	function addBingClub(){
		var clubId=$("#modifyInfo").find("#clubId").val(),playerId=$();
		if(clubId){
			if(clubId==$("#alreadyInfo").find("#clubId").html()){
				alert("该玩家已经绑定该俱乐部!");
				return false;
			}
			var clubInfo=$("#alreadyInfo").data("clubInfo");
			if(clubInfo && clubInfo["arrearage"] && parseInt(clubInfo["arrearage"])>0){
				alert("未结清账户前不能更换代理!请先结清所欠俱乐部余额");
				return false;
			}
			$.post("<%=request.getContextPath()%>/club/bindClub.html",{"clubId":clubId,"playerId":$("#addBingClub").data("playerId")},function(data){
				if(data){
					var result=$.parseJSON(data);
					if(!result["error"]){
						var club=result["data"];
						$("#modifyInfo").find("#clubSize").html(club["clubSize"]);
					}
					if(result["msg"]) alert(result["msg"]);
					$("#addBingClub").modal('hide');
					//$("#addBingClub").find("#addClubBtn").hide();
					//$("#addBingClub").find("#closeBtn").show();
				}
			},"json");
		}else{
			alert("请先选择俱乐部");
		}
	}
	function searchClub(el){
		var clubId=$(el).siblings("#clubId").val();
		if(clubId){
			$.post("<%=request.getContextPath()%>/club/getClubById.html",{"clubId":clubId},function(data){
				if(data){
					var result=$.parseJSON(data),club=result["data"];
					if(club && !result["error"]){
						$("#modifyInfo").find("#clubName").html(club["clubName"]);
						$("#modifyInfo").find("#clubSize").html(club["clubSize"]);
					}else{
						if(result["msg"]) alert(result["msg"]);
						else
							alert("没有查询到该俱乐部");
					}
				}
			},"json");
		}
	}
	function initModal(){
		$("#addBingClub").modal('hide').removeData();
		$("#addBingClub").find("#closeBtn").hide();
		$("#addBingClub").find("#addClubBtn").show();
		$("#alreadyInfo").find("#clubId").html("");
		$("#alreadyInfo").find("#clubName").html("");
		$("#alreadyInfo").hide();
		$("#modifyInfo").find("#clubName").html("");
		$("#modifyInfo").find("#clubSize").html("");
		$("#alreadyInfo").find("#surplusDiamond").html("");
		$("#modifyInfo").find("#clubId").val("");
	}
    //封号
    function gameTitel(playerId,obj) {
        var  parent=$(obj).parent().parent();
        var info= $(parent).find("td[name='playerState']").text();
        if(info=='是'){
           return;
        }

        if(confirm("确认封号？？")) {
            $.ajax({
                type: "POST",
                url: "<%=request.getContextPath()%>/player/updatePlayerInfo.html",
                data: {
                    "playerId": playerId,
                    "playerState": "1",
                },
                dataType: 'json',
                success: function (data) {

                    var row = data.sucessRow;
                    if (row > 0 ) {
                        $(parent).find("td[name='locked']").text("是");
                    }
                }
            });
        }

    }


    function canclePlayerRole(id,account,obj){
        if(confirm("确认取消用户代理管理员职责？")){
            var  parent=$(obj).parent().parent();
            $.ajax({
                type: "POST",
                url: "<%=request.getContextPath()%>/player/settingPlayerRole.html",
                data: {
                    "id": id,
                    "role": 0,
                },
                dataType: 'json',
                success: function (data) {
                    var row=data.sucessRow;
                    if(row>0){

                        $(parent).find("td[name='role']").text('玩家');
                    }
                    // alert(data.resultMessage);
                    resetAll();
                }
            });
        }
    }

    function settingPlayerRole(id,account,obj){
        if(confirm("确认将用户设置为代理管理员？")){
            var  parent=$(obj).parent().parent();
            $.ajax({
                type: "POST",
                url: "<%=request.getContextPath()%>/player/settingPlayerRole.html",
                data: {
                    "id": id,
                    "role": 1,
                },
                dataType: 'json',
                success: function (data) {
                    var row=data.sucessRow;
                    if(row>0){

                        $(parent).find("td[name='role']").text('代理管理员');
                    }
                   // alert(data.resultMessage);
                    resetAll();
                }
            });
        }
    }

    function clearPlayer(playerId,el){
    	 if(confirm("是否清除玩家异常数据?")){
    		 $.post("<%=request.getContextPath()%>/club/clearPlayer.html",{"playerId":playerId},function(data){
    			 alert(data["msg"]);
    		 },"json");
    	 }
    }
    
    //解封
    function deblocking(playerId,obj) {
        var  parent=$(obj).parent().parent();
        var info= $(parent).find("td[name='playerState']").text();
        if(info=='否'){
            return;
        }
        if(confirm("确认解封？？")) {
            $.ajax({
                type: "POST",
                url: "<%=request.getContextPath()%>/player/updatePlayerInfo.html",
                data: {
                    "playerId": playerId,
                    "playerState": "0",
                },
                dataType: 'json',
                success: function (data) {

                    var row = data.sucessRow;
                    if (row > 0 ) {
                        $(parent).find("td[name='locked']").text("否");
                    }
                }
            });
        }

    }



    //加砖div
    function showCionDiv(id,obj){
        $("#player_id").val(id);
        $("#addCoinDiv").dialog({
            title: "加砖",
            height: 300,
            width: 500,
            modal: true,
            open: function (event, ui) {
                $(".ui-dialog-titlebar-close", $(this).parent()).hide();
            },
            buttons: {
                "确定": function () {
                   if(!validate( $("#mahjong_coin").val())){
                   if(confirm("确认充值？")){
                       addCoin(obj,$(this));
                   }}

                },
                "取消": function () {
                    resetAll();
                    $(this).dialog("close");
                }
            }
        });
    }


    function validate(obj){
        var reg = new RegExp("^-?\\d+$");
        if(!reg.test(obj)){
            alert("请输入数字!");
            return true;
        }
        return false;
    }

    function addCoin(obj,obj1){
        var  parent=$(obj).parent().parent();
        $.ajax({
            type: "POST",
            url: "<%=request.getContextPath()%>/player/coinAdd.html",
            data: {
                "id": $("#player_id").val(),
                "mahjongCoin": $("#mahjong_coin").val(),
                "amount": $("#amount").val()
            },
            dataType: 'json',
            success: function (data) {

                var row=data.effectRow;
                if(row>0){
                    $(parent).find("td[name='diamond']").text(data.nowCoin);
                }
                alert(data.resultMessage);
                resetAll();
                $(obj1).dialog("close");
            }
        });
    }

    function  resetAll(){

        var myform = document.getElementById("addCoinForm");
        myform.reset();
    }

</script>

</html>